package com.compass.doctor.ui.home.viewmodel

import androidx.lifecycle.MutableLiveData
import com.compass.framework.ext.stringListToJson
import com.compass.framework.model.Diagnosis
import com.compass.framework.model.TemplateDetails
import com.compass.framework.model.VAServiceBean
import com.compass.framework.toast.TipsToast
import com.compass.network.callback.IApiErrorCallback
import com.compass.network.manager.ApiManager
import com.compass.network.viewmodel.BaseViewModel
import com.google.gson.JsonObject

/**
 * Description：
 * Date:2024/7/28 12:50
 */
class VAServiceViewModel : BaseViewModel() {


    val serviceLiveData = MutableLiveData<MutableList<VAServiceBean>?>() //服务产品列表
    val serviceCodeLiveData = MutableLiveData<String?>() //二维码地址


    fun getServicePatientList(
        pageNo: Int = 1,
        name: String,
        doctorId: String?
    ) {

        val params = JsonObject().apply {
            addProperty("page", pageNo)
            addProperty("perPage", 10)
            addProperty("name", name)
            addProperty("doctorId", doctorId)

        }

        launchUIWithResult(responseBlock = {
            ApiManager.api.getServicePatientList(params)
        }, errorCall = object : IApiErrorCallback {
            override fun onError(code: Int?, error: String?) {
                TipsToast.showTips(error)
                serviceLiveData.value = null
            }
        }) {
            if (it == null || it.items.isNullOrEmpty()) {
                serviceLiveData.value = null
            } else {
                serviceLiveData.value = it.items
            }
        }
    }


    fun generateQRCode(
        productId: String?,
        doctorId: String?
    ) {

        val params = JsonObject().apply {
            addProperty("productId", productId)
            addProperty("doctorId", doctorId)
        }
        launchUIWithResult(responseBlock = {
            ApiManager.api.generateQRCode(params)
        }, errorCall = object : IApiErrorCallback {
            override fun onError(code: Int?, error: String?) {
                TipsToast.showTips(error)
                serviceCodeLiveData.value=null
            }
        }) {
            serviceCodeLiveData.value=it
        }
    }


}